<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>

	<body>
		<!-- oss 上传控件一定要引入，否则oss插件无法正常使用 -->
		<div class="layui-form-item" id="oss_container" style="display: none;">
			<button id="selectfiles" class='layui-btn layui-btn-sm'>上传图片</button>
		</div>
		<!-- oss -->
		<div class="layui-fluid layui-card" id="altContent">

		</div>
	</body>
	<script src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/js/lib/jquery-1.10.2_d88366fd.js"></script>
	<script src="http://open.web.meitu.com/sources/xiuxiu.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/oss/lib/plupload-2.1.2/js/plupload.full.min.js"></script>
	<script src="js/oss/uploader.js"></script>
	<script>
		xiuxiu.setLaunchVars("customMenu", ["decorate", "facialMenu"]);
		/*第1个参数是加载编辑器div容器，第2个参数是编辑器类型，第3个参数是div容器宽，第4个参数是div容器高*/
		xiuxiu.embedSWF("altContent", 3, "100%", "100%");
		xiuxiu.onInit = function() {
			//设置保存模式为base64
			xiuxiu.setUploadType(3);
			xiuxiu.loadPhoto(url);
			xiuxiu.onSaveBase64Image = function(data, file_name, ext, id) {
				/**
				 * 构造File对象，oss接受的是File对象
				 * 这里使用了base64编码图片，构造File时，必须要base64转码再构造，否则文件就是错的
				 */
				ps_image = dataURLtoFile(data, file_name, ext);
				uploader.addFile([ps_image]);
				//上传文件
				$.autoUpload();
			}
		}

		//初始化上传控件
		uploader = $.initUploader({
			container: 'oss_container',
			multi_selection: true,
			done: function(up, file, info) {
				//设置文件信息
				info = eval('(' + info.response + ')');
			}
		});

		//将base64转换为文件
		var mime_base = {
			png: 'image/png',
			jpg: 'image/jpeg',
			jpeg: 'image/jpeg',
			gif: 'image/gif',
			bmp: 'image/bmp'
		};
		//将base64转换为文件
		function dataURLtoFile(data_url, file_name, ext) {
			var mime = mime_base[ext],
				bstr = atob(data_url),
				n = bstr.length,
				u8arr = new Uint8Array(n);
			while(n--) {
				u8arr[n] = bstr.charCodeAt(n);
			}
			return new File([u8arr], file_name, {
				type: mime
			});
		}
	</script>

</html>